const express = require('express')
const bodyParser = require('body-parser')
const chinaTime = require('china-time')
const cookieParser = require('cookie-parser')
const session = require('express-session')
const router = require('./src/router/router.js')

let app = express()

app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
app.use(cookieParser())
app.use(session({
	secret:'hey!ACG',
	resave:false,
	saveUninitialized:true
}))

app.use('/',express.static('./views'))
app.use('/',express.static('./dist'))
app.use('/',express.static('./dist/css'))
app.use('/',express.static('./dist/img'))
app.use('/',express.static('./dist/js'))

app.all('*', function(req, res, next) {
    // res.header("Access-Control-Allow-Origin", req.headers.origin);
    res.header("Access-Control-Allow-Origin", '*');
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    // res.header('Access-Control-Allow-Credentials',true);
		next();
});


app.use(router)
app.listen(8082,function(){
	console.log('success! server is running in port 8082 --- Runtime :'+ chinaTime())
})

app.get('/',function(req,res){
	res.sendFile(__dirname+'/dist/index.html')
})
